<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Sudoku.Web.MVC.Models.BoardModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Sudoku Solver
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<ul>
    <li><%= Html.ActionLink("Insert easy board","PrefillBoard",new {id=1}) %></li>
    <li><%= Html.ActionLink("Insert medium board","PrefillBoard",new {id=2}) %></li>
    <li><%= Html.ActionLink("Insert hard board","PrefillBoard",new {id=3}) %></li>
</ul>

<table class="sudoku">
    <tr>
    <td>
<span id="puzzleTitle">Enter your puzzle</span>

<% using (Html.BeginForm("Solve", "Sudoku")) 
   { %>
    <%
    for (int row = 0; row < 9; row++)
    {
        string cellClass = "cell";
        if (row == 0)
        {
            cellClass += " CellTopRow";
        }
        if (row == 8)
        {
            cellClass += " CellBottomRow";
        }

        if (row % 3 == 2)
        {
            cellClass += " Cellr3";
        }
            %>
            <ul class="row">
            <%
    for (int col = 0; col < 9; col++)
    {
        string colCellClass = string.Empty;

        if (col == 0)
        {
            colCellClass += " CellLeftColumn";
        }
        if (col == 8)
        {
            colCellClass += " CellRightColumn";
        }


        if (col % 3 == 2)
        {
            colCellClass += " Cellc3";
        }
            %>
            <li class="<%= cellClass + colCellClass %>"><span class="box" >
                <%
                    string cellValue = string.Empty;
                    if (Model.StartBoard != null && Model.StartBoard[row,col].CellValue.HasValue)
                    {
                        cellValue = Model.StartBoard[row, col].CellValue.Value.ToString();
                    }
                %>
                <input type="text" style="width:40px" name="<%= string.Format("row{0}|col{1}",row,col) %>" value="<%= cellValue %>" /></span>
            </li>
        <%
    }
        %>
            </ul>
    <%        
    } 
    %>
    <br /><br />

    <input type="submit" value="Solve Puzzle" />
    <%= Html.ActionLink("Clear Board","ClearBoard") %>

<% } %>


<%
    if (ViewData["ResultMessage"] != null)
    {
%>
        <h3><%= ViewData["ResultMessage"].ToString()%></h3>
<%
    }
%>

<!-- The EndBoard must be outside of the form otherwise its values will be posted as well -->
<% if (Model.EndBoard != null)
   { %>
 <%
    for (int row = 0; row < 9; row++)
    {
        string cellClass = "cell";
        if (row == 0)
        {
            cellClass += " CellTopRow";
        }
        if (row == 8)
        {
            cellClass += " CellBottomRow";
        }

        if (row % 3 == 2)
        {
            cellClass += " Cellr3";
        }
            %>
            <ul class="row">
            <%
    for (int col = 0; col < 9; col++)
    {
        string colCellClass = string.Empty;

        if (col == 0)
        {
            colCellClass += " CellLeftColumn";
        }
        if (col == 8)
        {
            colCellClass += " CellRightColumn";
        }


        if (col % 3 == 2)
        {
            colCellClass += " Cellc3";
        }
            %>
            <li class="<%= cellClass + colCellClass %>"><span class="box" >
                <%
                    string cellValue = string.Empty;
                    if (Model.EndBoard != null && Model.EndBoard[row,col].CellValue.HasValue)
                    {
                        cellValue = Model.EndBoard[row, col].CellValue.Value.ToString();
                    }
                %>
                <input type="text" style="width:40px" name="<%= string.Format("soln_row{0}|col{1}",row,col) %>" value="<%= cellValue %>" /></span>
            </li>
        <%
    }
        %>
            </ul>
    <%        
    } 
    %>

<%} %>

<br />

<% using (Html.BeginForm("QuickUpdate","Sudoku"))
   { %>
<br />
<div>Easy enter board <span class="note">(0 = empty)</span></div>
<%=
    Html.TextArea("startBoardString", Model.StartBoardString, 12, 15, null)
%>
<br />
<input type="submit" value="Quick update" />
<% } %>    
    </td>
    <td class="amazonRegion">
            <%
                Html.RenderPartial(@"~/Views/Amazon/AmazonAdPartialView.ascx",
                    new Sudoku.Web.MVC.Models.AmazonAdModel(ConfigurationManager.AppSettings["amazonAdTag"]));
            %>    
    </td>
    </tr>
</table>


</asp:Content>
